#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pii pair<int,int> 
using namespace std;

namespace Fastio {
const int L = 1 << 20;
inline char gc() {
    static char buf[L], *l = buf, *r = buf;
    if (l == r)
        r = (l = buf) + fread(buf, 1, L, stdin);
    return (l == r) ? EOF : *l++;
}
char obuf[L], *p = obuf;
inline void pc(char c) {
    if (p == obuf + L)
        fwrite(obuf, 1, L, stdout), p = obuf;
    *p++ = c;
}
inline void flush() { fwrite(obuf, 1, p - obuf, stdout); }
struct Reader {
    template <typename T>
    inline Reader& operator>>(T& x) {
        x = 0;
        short f = 1;
        char c = gc();
        while (!isdigit(c)) {
            if (c == '-')
                f = -1;
            c = gc();
        }
        while (isdigit(c)) x = 10 * x + (c - '0'), c = gc();
        x *= f;
        return *this;
    }
    Reader() {}
} cin;
struct Writer {
    template <typename T>
    inline Writer& operator<<(T x) {
        if (x < 0)
            pc('-'), x = -x;
        static short tp = 0, s[40];
        do
            s[++tp] = x % 10, x /= 10;
        while (x);
        while (tp) pc(s[tp--] + '0');
        return *this;
    }
    inline Writer& operator<<(const char* s) {
        int i = 0;
        while (s[i]) pc(s[i++]);
        return *this;
    }
    inline Writer& operator<<(char c) {
        pc(c);
        return *this;
    }
    Writer() {}
    ~Writer() { flush(); }
} cout;
#define cin Fastio::cin


#define cout Fastio::cout


}

bool st;
const int Maxn=2e5+7;
const int inf=2e9;
int n,Q;
int id[Maxn],dfn[Maxn],tot;
int dep[Maxn],top[Maxn],sz[Maxn],son[Maxn],fa[Maxn];
ll wt[Maxn];
vector<pii >e[Maxn];
int Log[Maxn];

struct Node{
	int id,v;
	inline friend bool operator <(const Node x,const Node y){
		return x.v<y.v;
	}
}stmax[18][Maxn],stmin[18][Maxn];

ll ans;

void dfs1(int u,int ft){
	fa[u]=ft; dep[u]=dep[ft]+1; sz[u]=1;
	for(auto i:e[u]){
		int v=i.fi,w=i.se;
		if(v==ft) continue;
		wt[v]=wt[u]+w;
		dfs1(v,u);
		sz[u]+=sz[v]; 
		if(sz[son[u]]<sz[v]) son[u]=v;
	}
}
void dfs2(int u,int tp){
	top[u]=tp;
	id[++tot]=u; dfn[u]=tot;
	if(son[u]) dfs2(son[u],tp);
	for(auto i:e[u]){
		int v=i.fi;
		if(v==son[u] or v==fa[u]) continue;
		dfs2(v,v);
	}
}
inline int LCA(int u,int v){
	while(top[u]!=top[v]){
		if(dep[top[u]]<dep[top[v]]) swap(u,v);
		u=fa[top[u]];
	}
	if(dep[u]>dep[v]) swap(u,v);
	return u;
}
inline int sublca(int l,int r){
	int k=Log[r-l+1];
	int u=min(stmin[k][l],stmin[k][r-(1<<k)+1]).id;
	int v=max(stmax[k][l],stmax[k][r-(1<<k)+1]).id;
	return LCA(u,v);
}

struct TREE{
	int l,r;
	vector<int>s;
}t[Maxn<<2];

void build(int u,int l,int r){
	t[u].l=l,t[u].r=r;
	if(l==r){
		t[u].s.emplace_back(dfn[l]);
		return ;
	}
	int mid=(l+r)>>1;
	build(u<<1,l,mid), build(u<<1|1,mid+1,r);
	
	t[u].s.resize(t[u<<1].s.size()+t[u<<1|1].s.size());
	merge(t[u<<1].s.begin(),t[u<<1].s.end(),t[u<<1|1].s.begin(),t[u<<1|1].s.end(),t[u].s.begin());
}
int querylst(int u,int l,int r,int x){
	if(t[u].l>=l and t[u].r<=r){
		if(t[u].s[0]>x) return 0;
		int it=lower_bound(t[u].s.begin(),t[u].s.end(),x)-t[u].s.begin();
		return t[u].s[it-1];	
	}
	int mid=(t[u].l+t[u].r)>>1,ret=0;
	if(l<=mid) ret=max(ret,querylst(u<<1,l,r,x));
	if(r>mid) ret=max(ret,querylst(u<<1|1,l,r,x));
	return ret;
}
int querynxt(int u,int l,int r,int x){
	if(t[u].l>=l and t[u].r<=r){
		if(t[u].s.back()<x) return n+1;
		int it=lower_bound(t[u].s.begin(),t[u].s.end(),x)-t[u].s.begin();
		return t[u].s[it];
	}
	int mid=(t[u].l+t[u].r)>>1,ret=n+1;
	if(l<=mid) ret=min(ret,querynxt(u<<1,l,r,x));
	if(r>mid) ret=min(ret,querynxt(u<<1|1,l,r,x));
	return ret;
}
bool ed;

int main(){
	freopen("memory.in","r",stdin);
	freopen("memory.out","w",stdout); 

	cin>>n>>Q;
	for(int i=2;i<=n;i++) Log[i]=Log[i>>1]+1;
	for(int i=1;i<n;i++){
		int u,v,w;
		cin>>u>>v>>w;
		e[u].emplace_back(v,w);
		e[v].emplace_back(u,w);
	}
	dfs1(1,0);
	dfs2(1,1);
	build(1,1,n);
	
	for(int i=1;i<=n;i++) 
		stmin[0][i].id=stmax[0][i].id=i,
		stmin[0][i].v=stmax[0][i].v=dfn[i];
	for(int i=1;i<=17;i++)
		for(int j=1;j+(1<<i)-1<=n;j++)
			stmin[i][j]=min(stmin[i-1][j],stmin[i-1][j+(1<<i-1)]),
			stmax[i][j]=max(stmax[i-1][j],stmax[i-1][j+(1<<i-1)]);
	 
	while(Q--){
		ll p,l,r;
		cin>>p>>l>>r;
		p^=ans,l^=ans,r^=ans;
		int lca=sublca(l,r),gc=LCA(lca,p);
		
		if(dfn[p]<=dfn[lca] and dfn[lca]<dfn[p]+sz[p]){
			ans=wt[lca]-wt[p];
			cout<<ans<<"\n";
			continue;
		}
		else if(dfn[lca]<=dfn[p] and dfn[p]<dfn[lca]+sz[lca]){
			int rs=querynxt(1,l,r,dfn[p]);
			rs=id[rs];
			if(dfn[p]<=dfn[rs] and dfn[rs]<dfn[p]+sz[p]){
				ans=0;
				cout<<ans<<"\n";
				continue;
			}
			int ls=querylst(1,l,r,dfn[p]);
			ls=id[ls];
			ls=LCA(ls,p), rs=LCA(rs,p); bool tag=0;
			if(dfn[ls]<=dfn[p] and dfn[p]<dfn[ls]+sz[ls]){
				gc=ls; lca=ls; tag=1;
			}
			if(dfn[rs]<=dfn[p] and dfn[p]<dfn[rs]+sz[rs]){
				
				if(tag and dep[rs]<=dep[ls]) ;
				else gc=rs,lca=rs;
			}
			ans=wt[p]+wt[lca]-2*wt[gc];
			cout<<ans<<"\n";
			
		}
		else{
			ans=wt[p]+wt[lca]-2*wt[gc];
			cout<<ans<<"\n";
		}
	}

	return 0;
}
/*
10 10
2 1 9907
3 2 8329
4 2 8402
5 4 3636
6 4 8747
7 4 3080
8 6 780
9 6 5414
10 9 3545
2 10 10
26107 26106 26101
4 9 10
14171 14166 14169
8958 8949 8949
36008 36014 36013
11485 11485 11472
3 9 9
30888 30894 30895
8404 8404 8411

5 4
3 1 2
1 5 1
2 3 3
3 4 4
2 3 5
2 1 7
0 7 7
5 5 2

*/
